import 'package:get/get.dart';
import 'package:getx_tutorial/app/data/models/news_model.dart';
import 'package:getx_tutorial/app/modules/home/news_repository.dart';

class HomeController extends GetxController with StateMixin<NewsList> {
  final INewsRepository repository;
  var currentIndex = 0.obs;
  var page = 1.obs;
  var type = 'top'.obs;

  HomeController({required this.repository});

  @override
  void onInit() {
    super.onInit();

    getNewsList(); // 初次调用
  }

  // 获取新闻列表
  Future<void> getNewsList() async {
    final res = await repository.getNewsList(type: type.value, page: page.value);

    print('==================-----------');
    print(res.toJson());
    
    change(res, status: RxStatus.success());
  }
}